import request from '@/utils/request'
const FormData = require('form-data')

function objectToFormData(obj) {
  const formData = new FormData()
  for (const key in obj) {
    if (obj.hasOwnProperty(key)) {
      formData.append(key, obj[key])
    }
  }
  return formData
}
export function login(data) {
  // data = new FormData(data)
  data = objectToFormData(data)
  return request({
    url: '/user',
    method: 'post',
    data
  })
}
// 配置
export function keys(data) {
  // data = objectToFormData(data)
  return request({
    url: '/keys',
    method: 'post',
    data: JSON.stringify(data),
    headers:
    {
      'Content-Type': 'application/json'
    }
  })
}
// 获取系统账号
export function min(data) {
  // data = objectToFormData(data)
  return request({
    url: '/min',
    method: 'post',
    data: JSON.stringify(data),
    headers:
    {
      'Content-Type': 'application/json'
    }
  })
}

export function getInfo(token) {
  return request({
    url: '/vue-element-admin/user/info',
    method: 'get',
    params: { token }
  })
}

export function logout() {
  return request({
    url: '/vue-element-admin/user/logout',
    method: 'post'
  })
}
